/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年4月16日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.studyjdk.queue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Type Produce
 * @Desc
 * @author 52489
 * @date 2020年4月16日
 * @Version V1.0
 */
public class Produce {

    BlockingQueue<String> queue = new LinkedBlockingDeque<>();

    public void produce(String string) {
        queue.add(string);
    }

    public String consume() {
        return queue.poll();
    }

    public static void main(String[] args) {
        Produce produce = new Produce();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 20; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    ;
                    String x = i + "adasdasds";
                    produce.produce(x);
                    System.out.println("生产：" + x);

                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("消费：" + produce.consume());
            }
        }).start();
    }

}
